Passed
Branch master (0c09a6)
by Stephan
01:45
created

button.js ➔ ... ➔ $.fn[NAME].noConflict   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
/*!
2
  * Bootstrap button.js v4.3.1 (https://getbootstrap.com/)
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
8
  typeof define === 'function' && define.amd ? define(['jquery'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = global || self, global.Button = factory(global.jQuery));
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, function ($) { 'use strict';
11
12
  $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
13
14
  function _defineProperties(target, props) {
15
    for (var i = 0; i < props.length; i++) {
16
      var descriptor = props[i];
17
      descriptor.enumerable = descriptor.enumerable || false;
18
      descriptor.configurable = true;
19
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
      Object.defineProperty(target, descriptor.key, descriptor);
21
    }
22
  }
23
24
  function _createClass(Constructor, protoProps, staticProps) {
25
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
26
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
27
    return Constructor;
28
  }
29
30
  /**
31
   * ------------------------------------------------------------------------
32
   * Constants
33
   * ------------------------------------------------------------------------
34
   */
35
36
  var NAME = 'button';
37
  var VERSION = '4.3.1';
38
  var DATA_KEY = 'bs.button';
39
  var EVENT_KEY = "." + DATA_KEY;
40
  var DATA_API_KEY = '.data-api';
41
  var JQUERY_NO_CONFLICT = $.fn[NAME];
42
  var ClassName = {
43
    ACTIVE: 'active',
44
    BUTTON: 'btn',
45
    FOCUS: 'focus'
46
  };
47
  var Selector = {
48
    DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
49
    DATA_TOGGLE: '[data-toggle="buttons"]',
50
    INPUT: 'input:not([type="hidden"])',
51
    ACTIVE: '.active',
52
    BUTTON: '.btn'
53
  };
54
  var Event = {
55
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY,
56
    FOCUS_BLUR_DATA_API: "focus" + EVENT_KEY + DATA_API_KEY + " " + ("blur" + EVENT_KEY + DATA_API_KEY)
57
    /**
58
     * ------------------------------------------------------------------------
59
     * Class Definition
60
     * ------------------------------------------------------------------------
61
     */
62
63
  };
64
65
  var Button =
66
  /*#__PURE__*/
67
  function () {
68
    function Button(element) {
69
      this._element = element;
70
    } // Getters
71
72
73
    var _proto = Button.prototype;
74
75
    // Public
76
    _proto.toggle = function toggle() {
77
      var triggerChangeEvent = true;
78
      var addAriaPressed = true;
79
      var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0];
80
81
      if (rootElement) {
82
        var input = this._element.querySelector(Selector.INPUT);
83
84
        if (input) {
85
          if (input.type === 'radio') {
86
            if (input.checked && this._element.classList.contains(ClassName.ACTIVE)) {
87
              triggerChangeEvent = false;
88
            } else {
89
              var activeElement = rootElement.querySelector(Selector.ACTIVE);
90
91
              if (activeElement) {
92
                $(activeElement).removeClass(ClassName.ACTIVE);
93
              }
94
            }
95
          }
96
97
          if (triggerChangeEvent) {
98
            if (input.hasAttribute('disabled') || rootElement.hasAttribute('disabled') || input.classList.contains('disabled') || rootElement.classList.contains('disabled')) {
99
              return;
100
            }
101
102
            input.checked = !this._element.classList.contains(ClassName.ACTIVE);
103
            $(input).trigger('change');
104
          }
105
106
          input.focus();
107
          addAriaPressed = false;
108
        }
109
      }
110
111
      if (addAriaPressed) {
112
        this._element.setAttribute('aria-pressed', !this._element.classList.contains(ClassName.ACTIVE));
113
      }
114
115
      if (triggerChangeEvent) {
116
        $(this._element).toggleClass(ClassName.ACTIVE);
117
      }
118
    };
119
120
    _proto.dispose = function dispose() {
121
      $.removeData(this._element, DATA_KEY);
122
      this._element = null;
123
    } // Static
124
    ;
125
126
    Button._jQueryInterface = function _jQueryInterface(config) {
127
      return this.each(function () {
128
        var data = $(this).data(DATA_KEY);
129
130
        if (!data) {
131
          data = new Button(this);
132
          $(this).data(DATA_KEY, data);
133
        }
134
135
        if (config === 'toggle') {
136
          data[config]();
137
        }
138
      });
139
    };
140
141
    _createClass(Button, null, [{
142
      key: "VERSION",
143
      get: function get() {
144
        return VERSION;
145
      }
146
    }]);
147
148
    return Button;
149
  }();
150
  /**
151
   * ------------------------------------------------------------------------
152
   * Data Api implementation
153
   * ------------------------------------------------------------------------
154
   */
155
156
157
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
158
    event.preventDefault();
159
    var button = event.target;
160
161
    if (!$(button).hasClass(ClassName.BUTTON)) {
162
      button = $(button).closest(Selector.BUTTON);
163
    }
164
165
    Button._jQueryInterface.call($(button), 'toggle');
166
  }).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
167
    var button = $(event.target).closest(Selector.BUTTON)[0];
168
    $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
169
  });
170
  /**
171
   * ------------------------------------------------------------------------
172
   * jQuery
173
   * ------------------------------------------------------------------------
174
   */
175
176
  $.fn[NAME] = Button._jQueryInterface;
177
  $.fn[NAME].Constructor = Button;
178
179
  $.fn[NAME].noConflict = function () {
180
    $.fn[NAME] = JQUERY_NO_CONFLICT;
181
    return Button._jQueryInterface;
182
  };
183
184
  return Button;
185
186
}));
187
//# sourceMappingURL=button.js.map
188